//
//  FQMineServiceCollectionViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/8/25.
//

import UIKit

class FQMineServiceCollectionViewCell: UICollectionViewCell {
    var buttonBlock : ((_ index : Int)->Void)?

    var model : FQMineServiceModel! {
        didSet {
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .white
        layer.cornerRadius = 8
        clipsToBounds = true
        
        let titleLb = QMUILabel(font: .rSFont(16), textColor: .color51)
        titleLb.text = "更多服务"
        titleLb.contentEdgeInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 0)
        titleLb.qmui_borderPosition = .bottom
        titleLb.qmui_borderColor = .color238
        titleLb.qmui_borderWidth = 1
        contentView.addSubview(titleLb)
        
        titleLb.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(44)
        }
        
        let btnTitle = [/*"银行卡",*/ "帮助中心", "设置", ""]
        var btnArray : [QMUIButton] = []
        for (index, str) in btnTitle.enumerated() {
            let button = QMUIButton(title: str, titleColor: .color51, font: .rSFont(14))
            button.spacingBetweenImageAndTitle = 5
            button.imagePosition = .top
            button.setImage(UIImage(named: "icon_mine_service\(index + 2)"), for: .normal)
            button.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
            button.tag = 10 + index + 1
            contentView.addSubview(button)
            btnArray.append(button)
        }
        btnArray.snp.makeConstraints { make in
            make.height.equalTo(83)
            make.top.equalTo(titleLb.snp.bottom)
        }
        btnArray.snp.distributeViewsAlong(axisType: .horizontal, fixedSpacing: 10, leadSpacing: 0, tailSpacing: 0)
    }
    
    @objc func buttonClick(_ button : QMUIButton) {
        if buttonBlock != nil {
            buttonBlock!(button.tag)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
